package com.kclm.se.nio;

import java.io.FileWriter;
import java.nio.CharBuffer;


public class FileChannelv2 {

	public static void main(String[] args) {
		String path = "files/nio-data2.txt";
		//
		/*try(FileChannel fc = new FileOutputStream(path).getChannel();
				Writer writer = Channels.newWriter(fc, "UTF-8");) {*/
		try(FileWriter writer = new FileWriter(path);) {
			//
			CharBuffer cb = CharBuffer.wrap("今天天气真不错呀!");
			
			//
			System.out.println("cb的容量："+cb.capacity());
			System.out.println("cb的limit："+cb.limit());
			System.out.println("cb的mark："+cb.mark());
			System.out.println("cb的position："+cb.position());
			
			
			//从缓存中读出
			while(cb.hasRemaining()) {
				char c = cb.get();
				writer.write(c);
				System.out.println(c);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
